package com.vecspace.dayu.code.ui.pojo;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.vecspace.data.model.IdEntity;
import com.vecspace.data.model.RowMapper;
import com.vecspace.dayu.code.template.pojo.IPageComponent;
import com.vecspace.dicttable.DictAll;

import javax.persistence.Table;
import javax.persistence.Transient;

import com.vecspace.utils.Convert;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/** DAYU-页面数据表格配置
 * @author wanghua
 */
@Entity
@Polymorphism(type = PolymorphismType.EXPLICIT)
@Table(name = "DAYU_CODE_UI_DATAGRID")
public class DataGrid implements IPageComponent, IdEntity, java.io.Serializable {

	private static final long serialVersionUID = -6276165418840175408L;
	public DataGrid(){

	}
	
	protected Long id;
	/**逻辑ID*/
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId(){
		return id;
	}
	/**逻辑ID*/
	public void setId(Long value){
		this.id = value;
	}


	protected Long tableId;
	/**数据表ID*/
	@Column(name = "TABLE_ID")
	public Long getTableId(){
		return tableId;
	}
	/**数据表ID*/
	public void setTableId(Long value){
		this.tableId = value;
	}

	private String platformType;//终端类型
	@Column(name = "PLATFORM_TYPE")
	public String getPlatformType() {
		return platformType;
	}
	public void setPlatformType(String platformType) {
		this.platformType = platformType;
	}

	private Boolean useRecurseQuery;
	/** 当存在目录表时，对叶子表是否使用递归查询,0否，1是 */
	@Column(name = "USE_RECURSE_QUERY")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getUseRecurseQuery() {
		return useRecurseQuery;
	}
	/** 当存在目录表时，对叶子表是否使用递归查询,0否，1是 */
	public void setUseRecurseQuery(Boolean useRecurseQuery) {
		this.useRecurseQuery = useRecurseQuery;
	}

	protected Boolean lineNumberColumn;
	/**行号列*/
	@Column(name = "LINE_NUMBER_COLUMN")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getLineNumberColumn(){
		return lineNumberColumn;
	}
	/**行号列*/
	public void setLineNumberColumn(Boolean value){
		this.lineNumberColumn = value;
	}

	protected Boolean chkboxColumn;
	/**勾选列*/
	@Column(name = "CHKBOX_COLUMN")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getChkboxColumn(){
		return chkboxColumn;
	}
	/**勾选列*/
	public void setChkboxColumn(Boolean value){
		this.chkboxColumn = value;
	}

	protected Boolean chkboxMultiChked;
	/**勾选列是否可多选*/
	@Column(name = "CHKBOX_MULTI_CHKED")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getChkboxMultiChked(){
		return chkboxMultiChked;
	}
	/**勾选列是否可多选*/
	public void setChkboxMultiChked(Boolean value){
		this.chkboxMultiChked = value;
	}

	protected Boolean pagination;
	/**是否分页*/
	@Column(name = "PAGINATION")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getPagination(){
		return pagination;
	}
	/**是否分页*/
	public void setPagination(Boolean value){
		this.pagination = value;
	}

	protected Integer pageSize;
	/**默认一页记录数*/
	@Column(name = "PAGE_SIZE")
	public Integer getPageSize(){
		return pageSize;
	}
	/**默认一页记录数*/
	public void setPageSize(Integer value){
		this.pageSize = value;
	}

	protected Boolean optrCellEditBtn;
	/**操作列-编辑*/
	@Column(name = "OPTR_CELL_EDIT_BTN")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getOptrCellEditBtn(){
		return optrCellEditBtn;
	}
	/**操作列-编辑*/
	public void setOptrCellEditBtn(Boolean value){
		this.optrCellEditBtn = value;
	}

	protected Boolean optrCellDelBtn;
	/**操作列-删除*/
	@Column(name = "OPTR_CELL_DEL_BTN")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getOptrCellDelBtn(){
		return optrCellDelBtn;
	}
	/**操作列-删除*/
	public void setOptrCellDelBtn(Boolean value){
		this.optrCellDelBtn = value;
	}

	protected Boolean optrCellInfoBtn;
	/**操作列-详情*/
	@Column(name = "OPTR_CELL_INFO_BTN")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getOptrCellInfoBtn(){
		return optrCellInfoBtn;
	}
	/**操作列-详情*/
	public void setOptrCellInfoBtn(Boolean value){
		this.optrCellInfoBtn = value;
	}

	protected Boolean optrCellFileBtn;
	/**操作列-附件*/
	@Column(name = "OPTR_CELL_FILE_BTN")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getOptrCellFileBtn(){
		return optrCellFileBtn;
	}
	/**操作列-附件*/
	public void setOptrCellFileBtn(Boolean value){
		this.optrCellFileBtn = value;
	}

//	protected Boolean optrCellLockData;
//	/**工具栏-数据锁定*/
//	@Column(name = "OPTR_CELL_LOCK_DATA")@Type(type="org.hibernate.type.NumericBooleanType")
//	public Boolean getOptrCellLockData(){
//		return optrCellLockData;
//	}
//	/**工具栏-编辑按钮*/
//	public void setOptrCellLockData(Boolean value){
//		this.optrCellLockData = value;
//	}


	protected Boolean toolbarAddBtn;
	/**工具栏-添加按钮*/
	@Column(name = "TOOLBAR_ADD_BTN")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getToolbarAddBtn(){
		return toolbarAddBtn;
	}
	/**工具栏-添加按钮*/
	public void setToolbarAddBtn(Boolean value){
		this.toolbarAddBtn = value;
	}

	protected Boolean toolbarDelBtn;
	/**工具栏-删除按钮*/
	@Column(name = "TOOLBAR_DEL_BTN")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getToolbarDelBtn(){
		return toolbarDelBtn;
	}
	/**工具栏-删除按钮*/
	public void setToolbarDelBtn(Boolean value){
		this.toolbarDelBtn = value;
	}

	protected Boolean toolbarEditBtn;
	/**工具栏-编辑按钮*/
	@Column(name = "TOOLBAR_EDIT_BTN")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getToolbarEditBtn(){
		return toolbarEditBtn;
	}
	/**工具栏-编辑按钮*/
	public void setToolbarEditBtn(Boolean value){
		this.toolbarEditBtn = value;
	}

//	protected Boolean toolbarLockData;
//	/**工具栏-数据锁定*/
//	@Column(name = "TOOLBAR_LOCK_DATA")@Type(type="org.hibernate.type.NumericBooleanType")
//	public Boolean getToolbarLockData(){
//		return toolbarLockData;
//	}
//	/**工具栏-编辑按钮*/
//	public void setToolbarLockData(Boolean value){
//		this.toolbarLockData = value;
//	}

	protected Boolean toolbarExpBtn;
	/**工具栏-编辑按钮*/
	@Column(name = "TOOLBAR_EXP_BTN")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getToolbarExpBtn(){
		return toolbarExpBtn;
	}
	/**工具栏-编辑按钮*/
	public void setToolbarExpBtn(Boolean value){
		this.toolbarExpBtn = value;
	}

	protected Boolean gridEditable;
	/**表格可编辑*/
	@Column(name = "GRID_EDITABLE")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getGridEditable(){
		return gridEditable;
	}
	/**表格可编辑*/
	public void setGridEditable(Boolean value){
		this.gridEditable = value;
	}

	protected Boolean gridColumnLine;
	/**列分割线是否显示*/
	@Column(name = "GRID_COLUMN_LINE")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getGridColumnLine(){
		return gridColumnLine;
	}
	/**列分割线是否显示*/
	public void setGridColumnLine(Boolean value){
		this.gridColumnLine = value;
	}

	protected Boolean gridEditSaveType;
	/**单元格实时保存,0非实时保存，1实时保存*/
	@Column(name = "GRID_EDIT_SAVE_TYPE")@Type(type="org.hibernate.type.NumericBooleanType")
	public Boolean getGridEditSaveType(){
		return gridEditSaveType;
	}
	/**单元格实时保存,0非实时保存，1实时保存*/
	public void setGridEditSaveType(Boolean value){
		this.gridEditSaveType = value;
	}

	protected String statPanelPos;
	public static final String StatPanelPos = "DAYU-CODE-021";
	/**表格展示形式*/
	@Column(name = "STAT_PANEL_POS")
	public String getStatPanelPos(){
		return statPanelPos;
	}
	/**表格展示形式*/
	public void setStatPanelPos(String value){
		this.statPanelPos = value;
	}
	@Transient
	public String getStatPanelPosCaption(){
		return DictAll.getCachedItemName(StatPanelPos, statPanelPos);
	}
	
	protected Integer ordnum;
	/**顺序号*/
	@Column(name = "ORDNUM")
	public Integer getOrdnum(){
		return ordnum;
	}
	/**顺序号*/
	public void setOrdnum(Integer value){
		this.ordnum = value;
	}

	protected Date createTime;
	/**记录创建时间*/
	@JsonIgnore(true)
	@Column(name = "CREATE_TIME")
	public Date getCreateTime(){
		return createTime;
	}
	/**记录创建时间*/
	public void setCreateTime(Date value){
		this.createTime = value;
	}
	@Transient
	@JsonIgnore(true)
	public String getCreateTimeStr(){
		if(createTime == null){
			return "";
		}
		String exp = "yyyy-MM-dd";
		String timestr = new java.text.SimpleDateFormat(exp).format(createTime);
		return timestr;
	}

	protected String createUser;
	/**记录创建人ID*/
	@Column(name = "CREATE_USER")
	public String getCreateUser(){
		return createUser;
	}
	/**记录创建人ID*/
	public void setCreateUser(String value){
		this.createUser = value;
	}

	private List<DataGridColumn> gridColumns;
	@JsonIgnore
	@Transient
	public List<DataGridColumn> getGridColumns() {
		return gridColumns;
	}

	public void setGridColumns(List<DataGridColumn> gridColumns) {
		this.gridColumns = gridColumns;
	}
	
	public void parseFrom(Map<String, Object> row){
		RowMapper rowMapper = new RowMapper(row);
		this.id = rowMapper.getLong("ID");
		this.tableId = rowMapper.getLong("TABLE_ID");
		this.platformType = rowMapper.getString("PLATFORM_TYPE");
		this.useRecurseQuery = rowMapper.getBoolean("USE_RECURSE_QUERY");
		this.lineNumberColumn = rowMapper.getBoolean("LINE_NUMBER_COLUMN");
		this.chkboxColumn = rowMapper.getBoolean("CHKBOX_COLUMN");
		this.chkboxMultiChked = rowMapper.getBoolean("CHKBOX_MULTI_CHKED");
		this.pagination = rowMapper.getBoolean("PAGINATION");
		this.pageSize = rowMapper.getInteger("PAGE_SIZE");
		this.optrCellEditBtn = rowMapper.getBoolean("OPTR_CELL_EDIT_BTN");
		this.optrCellDelBtn = rowMapper.getBoolean("OPTR_CELL_DEL_BTN");
		this.optrCellInfoBtn = rowMapper.getBoolean("OPTR_CELL_INFO_BTN");
		this.optrCellFileBtn = rowMapper.getBoolean("OPTR_CELL_FILE_BTN");
//		this.optrCellLockData = rowMapper.getBoolean("OPTR_CELL_LOCK_DATA");
		this.toolbarAddBtn = rowMapper.getBoolean("TOOLBAR_ADD_BTN");
		this.toolbarDelBtn = rowMapper.getBoolean("TOOLBAR_DEL_BTN");
		this.toolbarEditBtn = rowMapper.getBoolean("TOOLBAR_EDIT_BTN");
		this.toolbarExpBtn = rowMapper.getBoolean("TOOLBAR_Exp_BTN");
//		this.toolbarLockData = rowMapper.getBoolean("TOOLBAR_LOCK_DATA");
		this.gridEditable = rowMapper.getBoolean("GRID_EDITABLE");
		this.gridColumnLine = rowMapper.getBoolean("GRID_COLUMN_LINE");
		this.gridEditSaveType = rowMapper.getBoolean("GRID_EDIT_SAVE_TYPE");
		this.statPanelPos = rowMapper.getString("STAT_PANEL_POS");
		this.ordnum = rowMapper.getInteger("ORDNUM");
		this.createTime = rowMapper.getDate("CREATE_TIME");
		this.createUser = rowMapper.getString("CREATE_USER");
	}

	@Transient
	public boolean getHasOptColumn(){
		return Convert.toBoolean(this.optrCellEditBtn,false)
				|| Convert.toBoolean(this.optrCellDelBtn,false)
				|| Convert.toBoolean(this.optrCellInfoBtn,false)
				|| Convert.toBoolean(this.optrCellFileBtn,false);
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null)return false;
		if(id == null)return false;
		DataGrid other = (DataGrid)obj;
		return id.equals(other.id);
	}

	@Override
	public int hashCode() {
		if(id == null)return 0;
		return id.hashCode();
	}
}
